import java.util.ArrayList;
import java.util.Scanner;
public class userMangement {
    User s;
    ArrayList<User> user = new ArrayList<User>();

    public userMangement() {
        user.add(new User("admin", "123", "教务处"));
    }

    public void addUser(User s) {
        user.add(s);
    }

    public void Login() {
        boolean t = false;
        boolean s = true;
        Scanner scanner = new Scanner(System.in);
        System.out.println("欢迎来到龙院图书管理系统");
        System.out.println("1.登入  2.注册");
        int x = scanner.nextInt();
        if (x == 1) {
            while (s) {
                System.out.println("请输入用户名");
                String name = scanner.next();
                System.out.println("请输入密码");
                String password = scanner.next();
                for (int i = 0; i < user.size(); i++) {
                    if (user.get(i).Name.equals(name) && user.get(i).password.equals(password)) {
                        System.out.println("登入成功");
                        System.out.println(user.get(i).Name + "欢迎使用图书管理系统");
                        t = true;
                        s = false;
                        break;
                    }
                    if (i == user.size() - 1 && t == false) {
                        System.out.println("用户名或密码错误请重新输入");
                    }
                    continue;
                }
            }
        }
        if (x == 2) {
            boolean n = false;
            System.out.println("请输入所属部门");
            String home = scanner.next();
            System.out.println("请输入用户名");
            String name = scanner.next();
            System.out.println("请输入密码");
            String password = scanner.next();
            for (int i = 0; i < user.size(); i++) {
                if (user.get(i).Name.equals(name)) {
                    System.out.println("用户名已存在");
                    n = true;
                }
                if (i == user.size()-1 && n == true) {
                    User w = new User(name, password, home);
                    userMangement e = new userMangement();
                    e.addUser(w);
                    System.out.println("注册成功");
                    Login();
                }
            }
        }
    }
}